
$('#section1').on('change',function () {

    //检索框的值
    var section1_val = $('#section1 option:selected').val();

    //subType的值
    var subType ='所属领域';
    if(section1_val =='3'){
        subType = '研究领域';
    } else if(section1_val =='6') {

    }

//资源类型映射
    var resources = {
        '1':'xq',
        '2':'cg',
        '3':'zj',
        '4':'qy',
    };

//34个省、市、自治区的名字拼音映射数组
    var provinces = {
        //23个省
        "台湾省": "710000",
        "河北省": "130000",
        "山西省": "140000",
        "辽宁省": "210000",
        "吉林省": "220000",
        "黑龙江省": "230000",
        "江苏省": "320000",
        "浙江省": "330000",
        "安徽省": "340000",
        "福建省": "350000",
        "江西省": "360000",
        "山东省": "370000",
        "河南省": "410000",
        "湖北省": "420000",
        "湖南省": "430000",
        "广东省": "440000",
        "海南省": "460000",
        "四川省": "510000",
        "贵州省": "520000",
        "云南省": "530000",
        "陕西省": "610000",
        "甘肃省": "620000",
        "青海省": "630000",
        //5个自治区
        "新疆维吾尔自治区": "650000",
        "广西壮族自治区": "450000",
        "内蒙古自治区": "150000",
        "宁夏回族自治区": "640000",
        "西藏自治区": "540000",
        //4个直辖市
        "北京市": "110000",
        "天津市": "120000",
        "上海市": "310000",
        "重庆市": "500000",
        //2个特别行政区
        "港澳":"910000"
    };

//获取资源领域
    $.ajax({
        url: restUrl + '/index/resdomain',
        type:'get',
        dataType:'json',
        data:{
            type: resources[section1_val],
            subType: subType,
        },
        success:function (v) {
            if(v.code =='10000') {
                $('#section3').empty();
                $('#section3').append("<option value='-1' disabled selected>请选择一个产业领域</option>");
                var ly = [];
                for (var i=0;i<v.data.length;i++){
                    if(i<v.data.length-1){
                        $('#section3').append("<option value='" + (i+1) + "'>" + v.data[i][i+1] +"</option>");
                        ly.push(v.data[i][i+1]);
                    } else if(i == (v.data.length-1)){
                        $('#section3').append("<option value='" + (i+1) + "'>" + v.data[i][99] +"</option>");
                        ly.push(v.data[i][99])
                    }
                }
               sessionStorage.setItem("ly",ly);
            } else {
                console.log(v.message)
            }
        },
        error:function (data) {
            console.log(data)
        }
    });


//获取统计地域
    $.ajax({
        url: restUrl + '/index/libcount',
        type:'post',
        dataType:'json',
        contentType:'application/json;charset=utf-8',
        data:JSON.stringify({
            "formType": resources[section1_val],
            "site": "1",
            "sex": "0",
            "domain": "1",
            "education": "0",
            "degree": "0",
            "sites": null,
            "sexs": null,
            "domains": null,
            "educations": null,
            "degrees": null
        }),
        success:function (v) {
            if(v.code =='10000'){
                var countrys =[];
                var isTrue =true;

                for(var i=0;i<v.data.lib.length;i++) {
                    if(v.data.lib[i].country != ''){
                        countrys.push(v.data.lib[i].country);
                    }
                }
                for(var j=0;j<countrys.length;j++){
                    if(countrys.indexOf(countrys[j]) != 0){
                        isTrue = false;
                        break;
                    }
                }

                sessionStorage.setItem('isTrue',isTrue);

                if(isTrue){
                    var prov =[];
                    prov.push(countrys[0]);
                    prov.push(provinces[countrys[0]])

                    sessionStorage.setItem('prov',prov);

                    //拿到城市city填充下拉菜单
                    var city =[];
                    var cityKey =[];
                    var deProv = chinaProv[prov[1]];

                    for(var key in deProv){
                        cityKey.push(key);
                        city.push(deProv[key]);
                    }

                    if(city.length == 1){
                        deProv = chinaProv[cityKey[0]];
                        city.length = 0;

                        for(var k in deProv){
                            city.push((deProv[k]));
                        }
                    }

                    $('#section2').empty();
                    $('#section2').append("<option value='-1' disabled selected>请选择一个地理位置</option>");
                    for(var k=0;k<city.length;k++){
                        $('#section2').append("<option value='" + cityKey[k] + "'>" + city[k] +"</option>");
                    }

                }else {
                    var city =[];
                    var cityKey =[];
                    var deProv = chinaProv['86'];

                    sessionStorage.setItem('prov','');

                    for(var key in deProv){
                        cityKey.push(key);
                        city.push(deProv[key]);
                    }

                    $('#section2').empty();
                    $('#section2').append("<option value='-1' disabled selected>请选择一个地理位置</option>");
                    $('#section2').append("<option value='320000'>江苏省</option>");
                    for(var k=0;k<city.length;k++){
                        if(city[k] == '江苏省'){
                            continue;
                        } else {
                            $('#section2').append("<option value='" + cityKey[k] + "'>" + city[k] +"</option>");
                        }
                    }

                }

            } else {
                console.log(v.message)
            }
        },
        error:function (data) {
            console.log(data)
        }
    });

})


